
//
//  YZQNewsTableViewCell.m
//  SuperNews
//
//  Created by qiang on 16/1/12.
//  Copyright © 2016年 qiang. All rights reserved.
//

#import "YZQNewsTableViewCell.h"


@interface YZQNewsTableViewCell ()
@property (nonatomic, retain) UIImageView *imageV; /**< 图片 */
@property (nonatomic, retain) UILabel *titleL; /**< 条比 */
@property (nonatomic, retain) UILabel *shortIntroL; /**< 简介 */
@property (nonatomic, retain) UILabel *replyL; /**< 跟贴 */
@property (nonatomic, retain) UILabel *tagL; /**< 标识 */


@end
@implementation YZQNewsTableViewCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)createSubviews
{
    
    // 图片
    self.imageV = [[UIImageView alloc]init];
    [self.contentView addSubview:self.imageV];
    self.imageV.backgroundColor = [UIColor orangeColor];
    [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self.contentView.mas_left).offset(10.0);
        make.width.equalTo(@100);
        make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        
    }];
    
    
    // 标题
    self.titleL = [[UILabel alloc]init];
    [self.contentView addSubview:self.titleL];
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imageV.mas_right).offset(10);
        make.top.equalTo(self.imageV).offset(5);
        make.right.equalTo(self.contentView).offset(-5);
        make.height.equalTo(@(15));
        
    }];
    self.titleL.font = [UIFont systemFontOfSize:16.0];
    
    
    
    // 简介
    self.shortIntroL = [[UILabel alloc]init];
    [self.contentView addSubview:self.shortIntroL];
    [self.shortIntroL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self.titleL);
        make.top.equalTo(self.titleL.mas_bottom).offset(10);
        make.height.equalTo(@(40));
        
    }];
    self.shortIntroL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    self.shortIntroL.numberOfLines = 0;
    self.shortIntroL.font = [UIFont systemFontOfSize:14.0];
    
    
    // 跟贴
    self.replyL = [[UILabel alloc] init];
    [self.contentView addSubview:self.replyL];
    [self.replyL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.shortIntroL).offset(-12);
        make.width.equalTo(@70);

        make.top.equalTo(self.shortIntroL.mas_centerY).offset(5);
        make.height.equalTo(@20);
        
    }];
    self.replyL.textAlignment = NSTextAlignmentRight;
    self.replyL.font = [UIFont systemFontOfSize:14.0];
    self.replyL.textColor = [UIColor colorWithWhite:0.620 alpha:1.000];
    
    
}

#pragma mark- 传值方法
- (void)setNewsM:(NewsPageModel *)newsM
{
    NSURL *url = [NSURL URLWithString:newsM.imgsrc];
    [self.imageV sd_setImageWithURL:url placeholderImage:nil];
    
    
    self.titleL.text = newsM.title;
    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
    paraStyle.lineSpacing = 4;
    NSDictionary *attrDict = @{
                               NSParagraphStyleAttributeName: paraStyle,
                               NSFontAttributeName: [UIFont systemFontOfSize: 14.0]};
    
    CGFloat height = [AdjustLabelWidthToFitFontAppTools heightForContent:newsM.digest width:self.contentView.frame.size.width - 100 - 10 - 2 fontSize:40];
    CGRect frame = self.shortIntroL.frame;
    frame.size.height = height;
    self.shortIntroL.frame = frame;
    self.shortIntroL.attributedText = [[NSAttributedString alloc] initWithString:newsM.digest attributes: attrDict];
    
    
    if (newsM.replyCount != nil) {
        if (newsM.replyCount.integerValue >= 10000 ) {
            self.replyL.text = [NSString stringWithFormat:@"%.1ld万跟帖", newsM.replyCount.integerValue / 10000];
        }else{
            self.replyL.text = [NSString stringWithFormat:@"%@跟帖", newsM.replyCount];
        }
    }
    if ([self.newsM.skipType isEqualToString:@"special"])  {
        
        self.replyL.text = @"专题";
        self.replyL.textColor = [UIColor redColor];
        [self.replyL removeFromSuperview];
    }
    
    
}


@end
